//
//  YTStashForewarningScreenViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/9.
//

#import "YTStashForewarningScreenViewController.h"
#import "ScreenTableViewCell.h"
#import "DTChoosePersonListShowView.h"
#import "YTSelectStringShowView.h"
#import "PersonInCchargeShowView.h"
#import "TemplateFoundDetailsModel.h"
#import "TimeFrameShowView.h"
#import "DTChoosePersonListShowView.h"

@interface YTStashForewarningScreenViewController ()

@end

@implementation YTStashForewarningScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.StatusBarColor = NO;
    self.view.backgroundColor = KcolorHex(@"#FBFBFB");
    
    UIView * topview = [UIView new];
    topview.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(Knav_HeightX);
    }];
    
  
    
    MJWeakSelf
    UIView * backview = [UIView new].addClickBlock(^{
        [weakSelf popViewController];
    });
    [topview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(44);
        make.left.bottom.offset(0);
        make.width.offset(kwt(120));
    }];
    
    
    
    UIImageView * leftimg = kimageView(@"left_black_path");
    [backview addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.offset(kwt(10));
        make.centerY.offset(0);
    }];
    
    UILabel * leftlab = [DTKTool labelWithText:@"筛选" andFont:kCFont(18) andTextColor:KcolorHex(@"#333333")];
    [topview addSubview:leftlab];
    [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.offset(KTop/2);
    }];
    
    UIView * buttonview = [UIView new];
    buttonview.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:buttonview];
    [buttonview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(63) + KSafeAreaBottomHeight);
    }];
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#ECECEC");
    [buttonview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(0.5);
    }];
    
    UIButton * qxbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qxbtn.backgroundColor = KcolorHex(@"#F0F2F4");
    [qxbtn setTitle:@"重置" forState:UIControlStateNormal];
    [qxbtn setTitleColor:KcolorHex(@"#5A6066") forState:UIControlStateNormal];
    qxbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qxbtn];
    [qxbtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qxbtn];
    [qxbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(133));
        make.left.offset(kwt(15));
        make.top.offset(kwt(8));
    }];
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(195), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#2892FE") endColor:KcolorHex(@"#0366FE")];
    [qrbtn setTitle:@"确定" forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qrbtn];
    [qrbtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(195));
        make.right.offset(kwt(-15));
        make.top.offset(kwt(8));
    }];
    
    
    [self.view addSubview:self.tableview];
    self.tableview.backgroundColor = KcolorHex(@"#FBFBFB");
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(topview.mas_bottom);
        make.bottom.equalTo(buttonview.mas_top);
    }];
    
}


- (void)leftBtnClick{
    self.model.categoryIdName = @"";
    self.model.categoryId = @"";
    self.model.startTime = @"";
    self.model.endTime = @"";
    self.model.monthTime = nil;
    [self.tableview reloadData];
}

- (void)rightBtnClick{
    [self.navigationController popViewControllerAnimated:YES];

}


- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  
    return kwt(95);
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    if(indexPath.row < 1){
        ScreenStringTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ScreenStringTableViewCell"];
        if (cell == nil) {
            cell = [[ScreenStringTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScreenStringTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [self cell:cell andWithIndex:indexPath.row];
        return cell ;
    }
    ScreenTimeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ScreenTimeTableViewCell"];
    if (cell == nil) {
        cell = [[ScreenTimeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScreenTimeTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   MJWeakSelf
    [cell setName:@"预警时间" andStartTime:self.model.startTime andEndTime:self.model.endTime andBlock:^(NSString * _Nonnull StartTime, NSString * _Nonnull EndTime) {
        [TimeFrameShowView showviewWithTitle:@"请选择预警时间" andStartTime:self.model.startTime andEndTime:self.model.endTime andRightBlock:^(NSString * _Nonnull StartTime, NSString * _Nonnull EndTime) {
            weakSelf.model.endTime = EndTime;
            weakSelf.model.startTime = StartTime;
            [weakSelf.tableview reloadData];
        } andCZBlock:^{
            weakSelf.model.endTime = @"";
            weakSelf.model.startTime = @"";
            [weakSelf.tableview reloadData];
        }];
    }];
//    [self cell:cell andWithIndex:indexPath.row];
    return cell ;
}

- (void)cell:(ScreenStringTableViewCell *)cell andWithIndex:(NSInteger)index{
    MJWeakSelf
    if(index == 0){
        [cell setName:@"物品品类" andContent:self.model.categoryIdName andBlock:^(NSString * _Nonnull content) {
            [weakSelf openWPPL:content];
        }];
    }
}


///池塘编组
- (void)openWPPL:(NSString *)content{
    [self.view showBusyHUD];
    [SCNetManger warehousekindOptionWithDict: [NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            NSArray <getPondTissueListModel *>* array = [NSArray yy_modelArrayWithClass:getPondTissueListModel.class json:model.result ];
            getPondTissueListModel * mm = [getPondTissueListModel new];
            mm.children = array;
            if(self.model.categoryId.length > 0){
                [mm modelWithSeledID:self.model.categoryId];
            }
            MJWeakSelf
            [DTChooseKindListShowView showViewWithArray:array andBlock:^(getPondTissueListModel * _Nonnull pondModel) {
                weakSelf.model.categoryId = pondModel.ID;
                weakSelf.model.categoryIdName = pondModel.TJname;
                [weakSelf.tableview reloadData];
            } andCZBlock:^{
                weakSelf.model.categoryId = @"";
                weakSelf.model.categoryIdName = @"";
                [weakSelf.tableview reloadData];
            }];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}
@end
